<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>UMD Room Finder</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script type="text/javascript">

        function getXhrObject() {
          if (window.XMLHttpRequest) {      // code for IE7+, Firefox, Chrome, Opera, Safari
             return new XMLHttpRequest();
              }
          else{                             // code for IE6, IE5
            return new ActiveXObject("Microsoft.XMLHTTP");
             }
        };
        
        function getRooms(building){
            var buildingDiv = document.getElementById("buildingDiv")
      
            var xmlhttp = getXhrObject();                                       //outer ajax request
            xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById("buildingDiv").innerHTML=xmlhttp.responseText;
                    if(building = ""){return;}
                    }

                    var xmlhttp = getXhrObject();                               //inner ajax request
                        xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                                    document.getElementById("buildingDiv2").innerHTML=xmlhttp.responseText;
                                    }
                    }
                    xmlhttp.open("GET", "updateRooms2.php?Building_to="+building, true);
                    xmlhttp.send();
                }
            }
            xmlhttp.open("GET", "updateRooms.php?Building_from="+building, true);
            xmlhttp.send();
            };


<!--            if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
              }
            else
              {// code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            xmlhttp.onreadystatechange=function()
              {
                {
                  if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                    document.getElementById("buildingDiv").innerHTML=xmlhttp.responseText;
                    }
                 }
                xmlhttp.open("GET","updateRooms.php?Building_from="+building,true);
                xmlhttp.send();
               }-->

 
  

</script>

  </head>
  <body>

<style type="text/css">
body
{
background-color:#e5f5ff;
background-image:url(http://img.photobucket.com/albums/v627/lovkurama/Screenshot2011-10-03at53227PM.png);
background-repeat:repeat-x;
}
div.banner
{
text-align:left;
}
</style>

<div class="banner">

<img src="http://img.photobucket.com/albums/v627/lovkurama/Screenshot2011-10-11at103904AM.png" height=30>


<h1>Room Finder</h1>
<br>

<?php
	//make connection to server
	$link = mysql_connect('localhost', 'pott0180', 'ckersixt');
	if(!$link) {
		die('Could not connect: ' . mysql_error());
	}

	//select database
	$db_selected = mysql_select_db('soloono_roomFinder', $link);
	if (!$db_selected) {
		die('Cant use db soloono_roomFinder: ' . mysql_error());
	}



        $building_result = sprintf("SELECT name FROM Building");
        $building_query = mysql_query($building_result);
        $building_result2 = sprintf("SELECT name FROM Building");
        $building_query2 = mysql_query($building_result2);

        echo "<h3>Your Location</h3>";
        echo "<p><dd><h5>Building:</h5>";
      
            //Create Form and populate from database
            echo '<form action="results.php" method="get">';
            echo '<select name="Building_from" id="building_from" onchange="getRooms(this.value)">';
            while($building_array = mysql_fetch_array($building_query))
              {
              echo '<option value="'.$building_array["name"].'">'.$building_array["name"].'</option>';
              }
            echo "</select>";
            echo "</p>";

            //Populate second select from database
            echo "<div id='buildingDiv'>";
                            // populated in updateRooms.php
            echo '</div></dd>';


        // Destination

        echo "<h3>Your Destination</h3>";
        echo "<p><dd><h5>Building:</h5>";

            //Create Form and populate from database
            echo '<select name="Building_to" id="building_to" onchange="getRooms(this.value)">';
            while($building_array = mysql_fetch_array($building_query2))
              {
              echo '<option value="'.$building_array["name"].'">'.$building_array["name"].'</option>';
              }
            echo "</select>";

            //Populate second select from database
            echo "<div id='buildingDiv2'>";
                            // populated in updateRooms2.php
            echo '</div></dd>';


        echo '<INPUT TYPE="image" SRC="http://img.photobucket.com/albums/v627/lovkurama/button-1.png" width=100 ALT="Submit Form">';
    
        echo '</form>';
        echo "</p>";




        mysql_close($link);


       ?>

        <br />



<br><br>


</body>
</html>
